package day02;

import java.util.Scanner;

public class Test02 {

    public static void main(String[] args) {
        long[] total = new long[1000001];
        long sum = 0;
        init(total);
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        init(total);
        int num[] = new int[n + 1];
        int[] tree = new int[1000001];
        int[] tree2 = new int[1000001];
        int[] b = new int[n + 1];
        //求比该数大的的数
        for (int i = 1; i <= n; i++) {
            num[i] = sc.nextInt();
            add(num[i] + 1, 1, tree);
            int read = read(num[i], tree);
            b[i] = i - 1 - read;
            b[i] = b[i] - (read(num[i] + 1, tree) - read(num[i], tree) - 1);
        }
        //求比该数小的数（倒着遍历该数组）
        for (int i = n; i > 0; i--) {
            add(num[i] + 1, 1, tree2);
            int read = read(num[i], tree2);
            b[i] = b[i] + read;
        }
        for (int i = 1; i <= n; i++) {
            sum += total[b[i]];
        }
        System.out.println(sum);
    }

    private static void init(long[] total) {
        for (int i = 1; i < 1000001; i++) {
            total[i] = total[i - 1] + i;
        }
    }

    private static void add(int k, int num, int[] tree) {
        while (k < tree.length) {
            tree[k] += num;
            k += k & -k;
        }
    }

    private static int read(int k, int[] tree)//1~k的区间和
    {
        int sum = 0;
        while (k != 0) {
            sum += tree[k];
            k -= k & -k;
        }
        return sum;
    }
}